package com.example.wacoffee_manage.Service.Impl;

import com.example.wacoffee_manage.Mapper.EmployeeMapper;
import com.example.wacoffee_manage.Service.loginService;
import com.example.wacoffee_manage.pojo.Employee;
import com.example.wacoffee_manage.utils.JwtUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
@Slf4j
public class loginServiceImpl implements loginService {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public Employee login(Employee employee) {
        employee=employeeMapper.getEmpByUsername(employee.getUsername(),employee.getPassword());
        if(employee!=null){
            Map<String,Object> map=new HashMap<>();
            Integer id=employee.getId();
            map.put("id",id);
            String jwt= JwtUtil.generateJwt(map);
            employee.setJwt(jwt);
            return employee;
        }
        return null;
    }
}
